export default {
	data() {
		return {
			// 遮罩层
			loading: true,
			dataCount: 0,
			queryData: { pageNum: 1, pageSize: 10 },
			tableData: [],
			checkedIds: [],
			showSearch: true,
			formDialog: false,
			dataId: ''
		};
	},
	computed: {
		userId() {
			return Number(this.$route.query.id);
		},
		dictData() {
			return this.dict.type || {}
		}
	},
	watch: {
		userId: {
			handler(id) {
				if (!id) {
					this.$delete(this.queryData, 'userId');
				} else {
					this.$set(this.queryData, 'userId', id);
				}
				this.queryTableData();
			},
			immediate: true
		}
	},
	methods: {
		//查询列表数据
		queryTableData() {
			this.loading = true;
			this.getTableData();
		},

		//重置列表查询
		handleResetQuery() {
			this.queryData = {
				pageNum: 1,
				pageSize: 10
			}
			this.queryTableData();
		},

		//列表选中
		handleSelectionChange(selection, field) {
			this.checkedIds = selection.map(n => n[field]);
		},

		//打开表单
		handleOpenDialog(id) {
			this.dataId = !id ? '' : id;
			this.formDialog = true;
		},

		//删除数据
		handleDeleteData(id) {
			let ids = !id ? this.checkedIds : id;
			let modal = this.$modal.confirm('是否确认删除' + this.pageName + '记录编号为"' + ids + '"的数据项？');
			modal.then(() => this.deleteDataRequest(ids)).catch(() => {});
		},

		//删除数据请求
		async deleteDataRequest(ids) {
			let result = await this.delFunction(ids);
			if (result.code === 200) {
				this.$modal.msgSuccess('删除成功');
				this.queryTableData();
			}
		},

		//导出列表数据
		handleExportData(name) {
			this.download(this.exportUrl, this.queryData, `${name}_${new Date().getTime()}.xlsx`);
		}
	}
};